<!DOCTYPE html>
<html lang=cmn-Hans>

<head>
    <title>注册</title>
    {{template "admin/partials/html-head.html"}}
</head>

<body class="hold-transition register-page">
    <div class="register-box">
        <div class="register-logo">
            <a href="/admin"><b>Admin</b>LTE</a>
        </div>
        <div class="register-box-body">
            <p class="login-box-msg">注册</p>
            <form action="" method="post" onsubmit="return false;">
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" placeholder="名称" name="username">
                    <span class="glyphicon glyphicon-user form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="email" class="form-control" placeholder="邮箱" name="email">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="密码" name="password">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="确认密码" name="repassword">
                    <span class="glyphicon glyphicon-log-in form-control-feedback"></span>
                </div>
                <div class="row">
                    <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <input type="checkbox"> I agree to the <a href="#">terms</a>
                            </label>
                        </div>
                    </div>

                    <div class="col-xs-4">
                        <button type="submit" id="register" class="btn btn-primary btn-block btn-flat">注册</button>
                    </div>

                </div>
            </form>
            <a href="/admin/page/login" class="text-center">已注册，去登陆</a>
        </div>

    </div>

    <!-- jQuery 3 -->
    <script src="../../static/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="../../static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- iCheck -->
    <script src="../../static/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' /* optional */
            });

            $("#register").on("click", function () {
                let username = $("input[name=username]").val();
                let email = $("input[name=email]").val();
                let password = $("input[name=password]").val();
                let repassword = $("input[name=repassword]").val();
                let remember = $("input[name=remember]").val();
                if (remember == 'on') {
                    remember = true;
                }
                $.ajax({
                    url: '/registration',
                    type: 'post', //GET
                    async: true,    //或false,是否异步
                    contentType: 'application/json',
                    data: JSON.stringify({
                        username: username,
                        password: password,
                        repassword: repassword,
                        email: email,
                    }),
                    timeout: 5000,    //超时时间
                    dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend: function (xhr) {
                        console.log('发送前')
                    },
                    success: function (data, textStatus, jqXHR) {
                        if (data.code !== 0) {
                            console.log(data.msg)
                            alert("注册失败！")
                            return
                        }
                        alert("注册成功，请查收邮件完成验证后登陆");
                    },
                    error: function (xhr, textStatus) {
                        console.log('错误')
                    },
                    complete: function () {
                        console.log('结束')
                    }
                })
            });
        });
    </script>
</body>

</html>